import React from 'react';
import { Spin } from 'antd';

import { TRDefault } from '@/components/index.js';
import { ExplainTitle } from '../../../components';
import { titleMap } from '../../../dictionary';
import { ITitleType } from '../../../type';
import type { IDataListType, IMaintenancePlanModalType } from '../../../type';
import { List } from '../index';
import styles from './index.less';

interface IProps {
  /**
   * lodaing
   */
  loading?: boolean;
  /**
   * error
   */
  error?: boolean;
  /**
   * 数据源
   */
  data?: IDataListType[];
  /**
   * 编辑检修计划表
   */
  onEdit?: (record: IDataListType, type: IMaintenancePlanModalType, onReview?: any) => void;
}

const MaintenanceSchedule = (props: IProps) => {
  const { loading = false, error = false, data, onEdit } = props;

  return (
    <div className={styles.container}>
      <div className={styles.header}>
        <div className={styles.left}>
          <ExplainTitle title={titleMap[ITitleType.MAINTENANCE_SCHEDULE].title} />
        </div>
      </div>
      <div className={styles.content}>
        {loading ? (
          <Spin />
        ) : error ? (
          <div className={styles.empty}>
            <TRDefault type={'error'} message={'系统异常'} />
          </div>
        ) : data?.length ? (
          <div className={styles.list}>
            <List dataSource={data || []} onEdit={onEdit} />
          </div>
        ) : (
          <div className={styles.empty}>
            <TRDefault type="emptysm" />
          </div>
        )}
      </div>
    </div>
  );
};

export default MaintenanceSchedule;
